<template>
  <div class="student">
    <h1>学校名称：{{ name }}</h1>
    <h1>学校地址：{{ address }}</h1>
    <h1>接收School组件传递过来的数据{{ schoolData }}</h1>
  </div>
</template>
<script>
import pubsub from "pubsub-js"

export default {
  name: "Student",
  data() {
    return {
      name: "尚硅谷",
      address: "衡阳",
      schoolData: ""
    }
  },
  mounted() {
    // 订阅消息
    this.pub = pubsub.subscrib("getData", (message, {name, age}) => {
      this.schoolData = name + age
      console.log(message) // 消息名
    })

  },
  beforeDestroy() {
    // 取消订阅
    pubsub.unsubscribe(this.pub)
  }
};
</script>

<style>
.student {
  background-color: #DC143C;
}
</style>
